<title>后台管理员</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>关于我们</cite></a>
        <a><cite>合作伙伴</cite></a>
    </div>
</div>

<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <table class="layui-hide" id="table-instance" lay-filter="table-instance"></table>
                <script type="text/html" id="table-useradmin-webuser">
                    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                </script>
            </div>
        </div>
    </div>
</body>
<script>
    layui.use(['layedit', 'admin', 'upload', 'laydate', 'useradmin', 'table', 'form'], function() {
        var $ = layui.$,
            $ = layui.jquery,
            admin = layui.admin,
            setter = layui.setter,
            view = layui.view,
            table = layui.table,
            form = layui.form,
            leyer = layui.leyer,
            upload = layui.upload,
            laydate = layui.laydate,
            layedit = layui.layedit;

        form.render(null, 'layadmin-userfront-formlist');

        //监听搜索
        form.on('submit(LAY-user-front-search)', function(data) {
            var field = data.field;

            //执行重载
            table.reload('table-instance', {
                where: field
            });
        });

        table.render({
            elem: "#table-instance",
            url: setter.request.baseUrl + "/partner/admin/list",
            method: "get",
            headers: {
                token: layui.data("layuiAdmin").token
            },
            response: {
                statusName: "code",
                statusCode: 0,
                msgName: "msg",
                countName: "count",
                dataName: "list",
            },
            // where: {
            //     typeId: 1
            // },       //传给后端的数据
            cols: [
                [{
                    align: 'center',
                    field: "partnerId",
                    title: "ID",
                    width: "10%",
                }, {
                    field: "partnerName",
                    width: "30%",
                    align: 'center',
                    title: "名称",
                    sort: true
                }, {
                    field: "partnerLogo",
                    width: "28.2%",
                    align: 'center',
                    templet: "#img",
                    title: "公司logo"
                }, {
                    field: "url",
                    width: "25%",
                    align: 'center',
                    title: "官方链接"
                }, {
                    align: 'center',
                    title: "手动操作",
                    width: "7%",
                    toolbar: "#table-useradmin-webuser" //删除、编辑
                }]

            ],
            page: true, //分页
        });
        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function() {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $(document).on("click", ".table-check-img", function(e) {
            var json = {
                title: "审核图片",
                id: 0,
                start: 0,
                data: [{
                    alt: "",
                    pid: 1,
                    src: $(e.target).data("img"),
                      //原图地址
                    thumb: "",
                }, ],
            };
            console.log(json)
            if (json.data[0].src == null) {
                layer.msg("暂无图片", {
                    offset: "15px",
                    icon: "2",
                    time: 1000
                })
            } else {
                var result = json.data[0].src.split(",");
                var j = new Array;
                for (var i = 0; i < result.length; i++) {
                    let json = {
                        "src": result[i]
                    }
                    j[i] = json;
                }
                layer.photos({
                    photos: {
                        "data": j
                    },
                    anim: 1,
                });
            }
        });


        //删除模块
        table.on("tool(table-instance)", function(obj) {
            var data = obj.data;

            if (obj.event === "del") {
                layer.confirm("真的删除么", function(index) {
                    delAdminHandle({
                        partnerId: data.partnerId,
                    });

                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === "edit") {
                admin.popup({
                    title: "编辑合作伙伴",
                    area: ["400px", "400px"],
                    success: function(layero, index) {
                        view(this.id)
                            .render("user/administrators/orderform", data)
                            .done(function() {
                                let _data = data;
                                console.log(_data)
                                form.render(null, "layuiadmin-form-admin");
                                //富文本
                                var aa = layedit.build('demo');
                                layedit.setContent(aa, data.detail, false)
                                    //监听提交
                                form.on("submit(LAY-user-front-submit)", function(data) {
                                    var field = data.field;
                                    var aahtml = layedit.getContent(aa);
                                    field.detail = aahtml
                                    var releaseTime = field.releaseTime;
                                    var EndTime = field.endTime;
                                    field.releaseTime = new Date(releaseTime).getTime() / 1000;
                                    field.endTime = new Date(EndTime).getTime() / 1000;
                                    editUserHandle(Object.assign(_data, field));
                                    //提交 Ajax 成功后，关闭当前弹层并重载表格
                                    // adminAdd(field);
                                    layui.table.reload("table-instance");
                                    layer.close(index);
                                });
                            });
                    },
                });
            }
        });

        //编辑模块
        function editUserHandle(params) {
            admin.req({
                url: setter.request.baseUrl + "/partner/admin/save",
                data: JSON.stringify(params),
                type: "post",
                dataType: "json",
                contentType: "application/json",
                done: function(res) {
                    layui.table.reload("table-instance");
                },
            });
        }



        // });
        //删除
        function delAdminHandle(params) {
            console.log(params)

            //  debugger
            admin.req({
                //*****************需要替换****************
                url: setter.request.baseUrl + "/partner/admin/delete",
                data: {
                    ...params,
                },
                type: "post",
                done: function(res) {
                    layer.msg("删除成功"); //删除成功之后弹窗
                },
            });
        }



        admin.req({                
            url:  setter.request.baseUrl  +  "/ours/frontend/info",
                            type:   "get",
                            done:   function(res)  {                                    },
                        
        });
    })
</script>
<script type="text/html" id="img">
    <button type="button" class="layui-btn layui-btn-xs table-check-img" data-img="{{d.partnerLogo}}">查看图片</button>
</script>
<!-- <div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table-instance" lay-filter="table-instance"></table>
        </div>
    </div>
</div> -->
<!-- 团队管理图片 -->
<!-- <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>团队管理：图片上传</legend>
</fieldset>

<div class="layui-upload">
    <button type="button" class="layui-btn" id="test1">上传图片</button>
    <div class="layui-upload-list">
        <img class="layui-upload-img" id="demo1">
        <p id="demoText"></p>
    </div>
    <textarea name="" required lay-verify="required" placeholder="团队管理图片信息" class="layui-textarea"></textarea>
</div> -->

<!-- 上传荣誉资质图片 -->
<!-- <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>上传多张图片</legend>
</fieldset>

<div class="cont newDrugs">
    <div class="layui-upload">
        <button type="button" class="layui-btn" id="test2">多图片上传</button>
        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
            预览图：
            <div class="layui-upload-list" id="demo2"></div>
        </blockquote>
    </div>
    <textarea name="" required lay-verify="required" placeholder="荣誉描述" class="layui-textarea"></textarea>
</div> -->
<!-- <script>
        //单张图片上传
        var uploadInst = upload.render({
            elem: '#test1',
            url: setter.request.baseUrl + '/upload/admin/file' //改成您自己的上传接口
                ,
            before: function(obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            },
            done: function(res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
            },
            error: function() {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function() {
                    uploadInst.upload();
                });
            }
        });



        //多图片上传
        upload.render({
            elem: '#test2',
            url: setter.request.baseUrl + '/upload/admin/file' //改成您自己的上传接口 
                ,
            multiple: true,
            before: function(obj) {
                //预读本地文件示例，不支持ie8
                console.log(obj)
                obj.preview(function(index, file, result) {
                    $('#demo2').append('<img src="' + result + '" alt="' + file.name + '" class="layui-upload-img">')
                });
            },
            done: function(res) {
                //上传完毕
            }
        });

    })
</script> -->